<%@ taglib prefix="p" uri="/WEB-INF/tld/privilege.tld" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%     
	String path = request.getContextPath();     
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";     
%> 
<%response.setHeader("cache-control","public"); %>
<html>
 <head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  <title>系统操作列表</title>
  <base href="<%=basePath%>"/>
  <%@ include file="../../list_include.jsp"%>
  
  <style type="text/css"> 
	fieldset,table,tr,td {margin:0; padding:0;}
	td {padding:0 5px 0 10px;}
	form label {font-weight:bold;}
	#actionTable {margin:5px 0;}
  </style>

  <script type="text/javascript">
	$(document).ready(function() { 
       	$("#actionTable").tablesorter({theme:'green', widgets:['zebra', "resizable"]});
       	
       	$("#btn_pageUp").click(function(){
			var curPage = $("#curPage").val();
			$("#curPage").val(parseInt(curPage) - 1);
			$("#actionForm").submit();
       	});
       	
       	$("#btn_pageDown").click(function(){
       		var curPage = $("#curPage").val();
			$("#curPage").val(parseInt(curPage) + 1);
			$("#actionForm").submit();
       	});

        $("#btn_insert").click(function(){
            var queryString = $("#actionForm").formSerialize();
            queryString = encodeURIComponent(queryString);
            location.href = "<%=basePath%>system/action/insert.do?qs=" + queryString;
        });
        
        $("#btn_search").click(function(){
            $("#curPage").val(1);
            $("#actionForm").submit();
        });

        $("#btn_change").click(function(){
            var page = parseInt($("#selectPage").val());
            var curPage = parseInt($("#curPage").val());
            if(curPage == page) return;
            $("#curPage").val(parseInt(page));
            $("#actionForm").submit();
        });
        
        $.ajaxSetup ({ cache:false });
	});  
	
    function edit(id){
        var queryString = $("#actionForm").formSerialize();
        queryString = encodeURIComponent(queryString);
        location.href = "<%=basePath%>system/action/edit.do?id=" + id + "&qs=" + queryString;
    }
	
	function del(id) {
		if(confirm("确定删除该对象？") != 1) return;
		
		$.get("system/action/delete.do", {id:id}, function(data) {
			var result = $.parseJSON(data);
			if(result.code == 1) {
				alert("删除成功!");
				$("#btn_search").click();
			} else {
				alert(result.message);
			}
		});
	}
  </script>
 </head>

 <body>
  <div>
    <fieldset>
      <legend>查询条件：</legend>
      <form id="actionForm" method="post" action="system/action/list.do">
        <table>
          <tr>
            <td><label for="enname">英文名称：</label></td>
            <td><input type="text" name="enname" id="enname" value="${enname}" style="width:150px;" /></td>
            <td><label for="alias">中文名称：</label></td>
            <td><input type="text" name="alias" id="alias" value="${alias}" style="width:150px;" /></td>
            <td><label for="moduleName">所属模块：</label></td>
            <td>
                <select id="moduleName" name="moduleName" style="width:120px;">
                   <option value="" style="color:red">选择模块</option>
                <c:forEach var="module" items="${moduleList}" varStatus="status">
                   <option value="${module.enname}" <c:if test="${module.enname == moduleName}">selected</c:if>>${module.alias}</option>
                </c:forEach>
              	</select>             	
            </td>                    
            <td><input type="submit" id="btn_search" name="btn_search" value="查询" style="width:80px;" /></td>
          </tr>
        </table>
        <input type="hidden" name="curPage" id="curPage" value="${curPage}" />
      </form>
    </fieldset>
  </div>
  
  <div>
  	<table id="actionTable" class="tablesorter">
	  <thead> 
	    <tr> 
          <th>英文名称</th> 
	      <th>中文名称</th>
	      <th>所属模块</th>
	      <th>操作URL</th> 
	      <th>创建时间</th> 
	      <th>操作</th> 
 	    </tr> 
	  </thead>
	  <tbody>
	  	<c:forEach items="${actionList}" var="action" varStatus="status">
	  	<tr>
	  	  <td>${action.enname }</td>
	  	  <td>${action.alias }</td>
	  	  <td>${mdNameMap[action.moduleName]}</td>
	  	  <td>${action.url }</td>
	  	  <td>${action.createTime }</td>
	  	  <td>
	  	  	<a href="system/action/view.do?id=${action.id}">查看</a>
	  	  	<p:chkPri actionUrl="system/action/edit.do"><a href=# onclick="javascript:edit('${action.id}'); return false;">修改</a></p:chkPri>
	  	  	<p:chkPri actionUrl="system/action/delete.do"><a href=# onclick="javascript:del('${action.id}'); return false;">删除</a></p:chkPri>
	  	  </td>
	  	</tr>
	  	</c:forEach>
	  </tbody>
  	</table>
  </div>

  <div>
      <div style="float:left;">
        <p:chkPri actionUrl="system/action/insert.do"><input id="btn_insert" type="button" value="新增" /></p:chkPri>
      </div>

      <div style="text-align:right;">
        <c:if test="${curPage <= 1}"><input type="button" disabled="disabled" id="btn_pageUp" value="上一页"/></c:if>
        <c:if test="${curPage > 1}"><input type="button" id="btn_pageUp" value="上一页"/></c:if>
        <c:if test="${curPage >= totalPage}"><input type="button" id="btn_pageDown" disabled="disabled" value="下一页"/></c:if>
        <c:if test="${curPage < totalPage}"><input type="button" id="btn_pageDown" value="下一页"/></c:if>
        共${totalPage}页/共${totalRecords}条
        <select id="selectPage" style="width: auto;">
            <c:forEach var="i" begin="1" end="${totalPage}">
                <option id="${i}" <c:if test="${i == curPage}">selected="selected"</c:if>>${i}</option>
            </c:forEach>
        </select>
        <input id="btn_change" type="button" value="转至" />
      </div>
  </div>
 </body>
</html>

